﻿package cn.poco.xw.activity.tab;


/*import cn.poco.food.R;
import cn.poco.food.discount.DiscountTabActivity;
import cn.poco.food.init.SwitchCityActivity;
import cn.poco.food.more.activity.FoodActivity;
import cn.poco.food.review.ReviewActivity;
import cn.poco.food.search.SearchResActivity;
import cn.poco.food.search.TabSearchActivity;
import cn.poco.food.topic.ExcavationActivity;
import cn.poco.util.Constants;*/


import cn.poco.constants.Constants;

import cn.poco.pepsi.TabTest;
import cn.poco.xw.R;
import cn.poco.xw.activity.init.SwitchCityActivity;
import cn.poco.xw.activity.search.TabSearchActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

/**
 * @author Administrator
 *该类用于显示闲聊主页的页签，并启动
 *每个页签对应的Activity
 */
public class TabActivity extends android.app.TabActivity {
	
	public static TabHost tabs;;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.main_tab);
		
		//获取InitActivity传过来的城市名及代码
		String citycode = getIntent().getExtras().get(Constants.CITY_CODE).toString();
		String cityname = getIntent().getExtras().get(Constants.CITY_NAME).toString();
		System.out.println("获取InitActivity传过来的城市名及代码-------------->"+citycode+"&&"+cityname);
		
		tabs = getTabHost(); 
		
	    final TabWidget tabWidget = tabs.getTabWidget();

	    FrameLayout tabcontent = (FrameLayout)findViewById(android.R.id.tabcontent);
	    
	    //搜索Tab
        TabHost.TabSpec searchTab = tabs.newTabSpec("搜索");
        Intent searchIntent = new Intent(this, TabSearchActivity.class);
        searchTab.setContent(searchIntent);
        searchIntent.putExtra("tT", "搜索");
       searchIntent.putExtra(Constants.CITY_NAME, cityname);
       searchIntent.putExtra(Constants.CITY_CODE, citycode);
        searchTab.setIndicator(createTabView("搜索",R.drawable.search_tab));
        tabs.addTab(searchTab);
     //附近Tab
        TabHost.TabSpec nearTab = tabs.newTabSpec("附近");
        Intent nearIntent = new Intent(this, TabTest.class);
        nearTab.setContent(nearIntent);
        nearIntent.putExtra("tT", "附近");
       nearIntent.putExtra(Constants.NEAR_MODULE, "near");
        nearTab.setIndicator(createTabView("附近",R.drawable.near_tab));
        tabs.addTab(nearTab);
       
       //优惠
        TabHost.TabSpec favourableTab = tabs.newTabSpec("优惠");
        Intent favourableIntent = new Intent(this, TabTest.class);
        favourableTab.setContent(favourableIntent);
       favourableIntent.putExtra("tT", "优惠");
        favourableTab.setIndicator(createTabView("优惠",R.drawable.ticket_tab));
        tabs.addTab(favourableTab);
      
        
        
        //签到
        TabHost.TabSpec subjectTab = tabs.newTabSpec("签到");
        Intent subjectIntent = new Intent(this, TabTest.class);
        subjectTab.setContent(subjectIntent);
        subjectIntent.putExtra("tT", "签到");
        subjectTab.setIndicator(createTabView("签到",R.drawable.checkin_tab));
        tabs.addTab(subjectTab);
        
        //i百事
        TabHost.TabSpec moreTab = tabs.newTabSpec("i百事");
        Intent moreIntent = new Intent(this, TabTest.class);
        moreTab.setContent(moreIntent);
        moreIntent.putExtra("tT", "i百事");
        moreTab.setIndicator(createTabView("i百事",R.drawable.ipepsi_tab));
        tabs.addTab(moreTab);
        
        
        
        
       int height = getResources().getDrawable(R.drawable.tab_selected).getIntrinsicHeight();
       tabcontent.setPadding(0, 0, 0, height+(height/3)-2);
        for(int i=0;i<tabWidget.getChildCount();i++){
        	View currentview = tabWidget.getChildAt(i);
        	currentview.setBackgroundResource(R.drawable.res_main_tab);
        	currentview.getLayoutParams().height = height+(height/3);
        }
        this.setTitle("美食天堂-"+"搜索");
 
        /*//遮住底边
        tabs.setPadding(tabs.getPaddingLeft(),
        		tabs.getPaddingTop(), tabs.getPaddingRight(), 
        		tabs.getPaddingBottom()-6);*/
         
        
   }
	
	
	
	//创建Tab视图方法：
	public View createTabView(String text,int iconId){
		DisplayMetrics dm = new DisplayMetrics();  
		getWindowManager().getDefaultDisplay().getMetrics(dm); 
		LayoutParams params = new LayoutParams(dm.widthPixels/5, LayoutParams.FILL_PARENT);
		LinearLayout layout = new LinearLayout(this);
		layout.setLayoutParams(params);
		layout.setGravity(Gravity.CENTER);
		layout.setOrientation(LinearLayout.VERTICAL);
		layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.res_main_tab));
		ImageView imageView = new ImageView(this);
		imageView.setImageResource(iconId);
		layout.addView(imageView);
		TextView textView = new TextView(this);
		textView.setGravity(Gravity.CENTER);
		textView.setText(text);
		textView.setTextColor(Color.WHITE);
		layout.addView(textView);
		return layout;
	}

public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.menu, menu);
		return true;
	}
	
	
	
	//系统菜单选项[最近浏览、切换城市、关于、退出]
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int item_id = item.getItemId();
		switch (item_id) {
		/*case R.id.recentlyviewed:
			Intent reviewIntent = new Intent(TabActivity.this,ReviewActivity.class);
			startActivity(reviewIntent);
			break;*/
		case R.id.switchcity:
			Intent switchIntent = new Intent(TabActivity.this, SwitchCityActivity.class);
			startActivity(switchIntent);
			break;
	    //关于：静态界面
		/*case R.id.about:
			Intent aboutIntent = new Intent(TabActivity.this, AboutActivity.class);
			startActivity(aboutIntent);
			break;
		case R.id.exit:
			Constants.exit = "stop";
			finish();
			break;*/
		}
		
		return true;
	}
	
	@Override
	protected void onResume() {
		super.onResume();
//		if(Constants.exit.equals("stop")){
//			finish();
//		}
	}
	
	
	
	
	
     
}
